package com.wpzf.zxhc.controller;

import com.wpzf.common.core.utils.ServletUtils;
import com.wpzf.common.core.web.domain.AjaxResult;
import com.wpzf.common.log.annotation.Log;
import com.wpzf.common.log.enums.BusinessType;
import com.wpzf.common.security.utils.SecurityUtils;
import com.wpzf.system.api.model.LoginUser;
import com.wpzf.zxhc.domain.WpCjdataUploadDTO;
import com.wpzf.zxhc.service.DataProcessService;
import com.wpzf.zxhc.service.ProvAuditingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.*;

//数据处理
@RestController
@RequestMapping("/dataprocess")
public class DataProcessController
{

    @Autowired
    ProvAuditingService provAuditingService;
    @Autowired
    DataProcessService dataProcessService;


    @RequestMapping(value = "/clip", method = RequestMethod.POST)
    public AjaxResult shpclip(@RequestBody Map<String, Object> parm)
    {
        return AjaxResult.error("获取当前单位所有的人员失败", -1);
    }
    @Log(title = "数据导入", businessType = BusinessType.OTHER)
    @RequestMapping(value = "/uploadFileZip", method = RequestMethod.POST)
    public AjaxResult uploadFileZip(MultipartFile file) {
        try
        {
            //获得文件名称
            String fileName = file.getOriginalFilename();

            //获得文件后缀名
            String type = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();

            //判断上传的是否是压缩包
            if (!type.equals("zip") && !type.equals("rar")) {
                return AjaxResult.error("请上传文件压缩包");
            }
            String sFilePath = provAuditingService.uploadFile(file); //上传文件
//            String sFilePath = "D:\\Tomcat8.5\\webapps\\cliptest.zip"; //上传文件路径
            if (sFilePath != "")
            {
                Map<String, Object>  result =dataProcessService.shptowkt(sFilePath);
                if(result.get("res").toString().equals(""))
                {
                    return AjaxResult.success("数据导入成功",result.get("data"));
                }
                else
                {
                    return AjaxResult.error("数据导入失败", result.get("res").toString());
                }
            }
        } catch (Exception ex) {
            return AjaxResult.error("数据导入失败", ex.toString());
        }
        return AjaxResult.error("数据导入失败");
    }

}
